<{if $goods.product}>
<{assign var=product value=$goods.product|current}>
<{/if}>
<input type='hidden' name='goods[product][0][status]' value='true'/>
<input type='hidden' name='goods[product][0][product_id]' value='<{$product.product_id}>'>
<table border="0" cellpadding="0" cellspacing="0" id="nospec_body"  class="advui">
<tbody>
    <{if $goods.type.is_physical}>
      <tr>
        <th><{t}>销售单位：<{/t}></th>
        <td>
			<{input type="select" required="true" name="goods[unit]" options=$unit value=$goods.unit onchange='unit_change(this)'}>
		</td>
      </tr>
	  <script>
		
	  </script>
	  <tr>
        <th><{t}>包装方式：<{/t}></th>
        <td>
			<span class='bag-unit'>1&nbsp;<{$goods.unit}>&nbsp;=</span>
			<{input type="digits" class="unit-num" required="true" name="goods[unit_num]" value=$goods.unit_num|default:1 style='width:25px;'}>&nbsp;&nbsp;
			<{input type="select" required="true" class="bag-unit1" name="goods[bag_unit]" options=$bag_unit value=$goods.bag_unit}>
		</td>
      </tr>
      <{/if}>
  <tr>
    <th><{t}>商品单价：<{/t}></th>
    <td>
      <{input type="text" class="s-price" name="goods[product][0][price][price][s_price]" value=$product.price.price.s_price style='width:60px;' maxlength="25"}>&nbsp;&nbsp;
    </td>
  </tr>
  <tr>
    <th><{t}>销售价：<{/t}></th>
    <td>
      <{permission perm_id='editprice'}>
      <{input vtype="unsigned" key="price" class="inputstyle sale-price" readonly="true" value=$product.price.price.price name="goods[product][0][price][price][price]" style="width:60px" maxlength="25" }>
      <{/permission}>
        <{permission perm_id='editmemberlevelprice'}>
        <{button type="button" label=$___b2c="编辑会员价格"|t:'b2c' onclick="goodsEditor.mprice.bind(goodsEditor)(this)" icon="btn_edit.gif" app='desktop'}>
        <{/permission}>
        <span>
    <{foreach from=$mLevels item=lv }>
    <input type="hidden" key="member_lv_price_<{$lv.member_lv_id}>" name="goods[product][0][price][member_lv_price][<{$lv.member_lv_id}>]" level="<{$lv.member_lv_id}>" value="<{if $product.price.member_lv_price[$lv.member_lv_id][custom] == 'true'}><{$product.price.member_lv_price[$lv.member_lv_id][price]}><{/if}>" type="money" vtype="mprice" />
      <{/foreach}>
      </span><!--tag_foreign_nospec-->
      </td>
  </tr>
  <tr>
    <th><{t}>采购价：<{/t}></th>
    <td>
    <{permission perm_id='editcostprice'}>
    <{input class='cost-price' vtype="unsigned" key="cost" name="goods[product][0][price][cost][price]" maxlength="30" style="width:60px" value=$product.price.cost.price }>
    <{/permission}>
    <span class="notice-inline"><{t}>前台不会显示，仅供后台使用。<{/t}></span></td>
  </tr>
  
  <tr>
    <th><{t}>市场价：<{/t}></th>
    <td>
    <{permission perm_id='editmktprice'}>
    <{input vtype="unsigned" key="mktprice" name="goods[product][0][price][mktprice][price]" maxlength="30" style="width:60px" value=$product.price.mktprice.price }>
    <{/permission}>
    </td>
  </tr>
	<tr>
		<th><{t}>阶梯价格：<{/t}></th>
		<td class='ladder-open <{if $goods.ladder.is_open=='true'}>hide<{/if}>'><{button label=$___b2c="开启阶梯价"|t:'b2c' app="desktop" type="button" onclick="open_ladder()" icon="btn_add.gif"}></td>
		<td  class='ladder-close  <{if $goods.ladder.is_open!='true'}>hide<{/if}>'><{button label=$___b2c="关闭阶梯价"|t:'b2c' app="desktop" type="button" onclick="close_ladder()" icon="btn_add.gif"}></td>
		<input class='is-open' type='hidden' name='goods[ladder][is_open]' value='<{$goods.ladder.is_open}>'>
	</tr>
	<tr class='ladder <{if $goods.ladder.is_open!='true'}>hide<{/if}>'>
		<th><label><{t}>阶梯数量：<{/t}></label></th>
		<td><input type='text' class='ladder-num inputstyle' name='goods[ladder][ladder_num]' value='<{$goods.ladder.ladder_num}>'  style="width:60px" maxlength="25" vtype='unsigned'/><span class='rebate-tips' style='display:none'><{help}><{t}>阶梯数量不能小于2!当前结算方式为返点，维护销售价，采购价=销售价*(1-返点率)<{/t}><{/help}></span>
		<span class='account-tips' style='display:none'><{help}><{t}>阶梯数量不能小于2!当前结算方式为结算价，维护采购价，销售价=采购价/(1-返点率)<{/t}><{/help}></span>
		</td>
	</tr>
	<tr class='ladder <{if $goods.ladder.is_open!='true'}>hide<{/if}>'>
		<th><label><{t}>阶梯销售价：<{/t}></label></th>
		<td>
		<input type='text' class='ladder-price inputstyle' name='goods[ladder][ladder_price]' id='ladder_price' value='<{$goods.ladder.ladder_price}>' vtype='positive'  style="width:60px" maxlength="25"/></td>
	</tr>
	<tr class='ladder <{if $goods.ladder.is_open!='true'}>hide<{/if}>'>
		<th><label><{t}>阶梯采购价：<{/t}></label></th>
		<td><input type='text' class='ladder-cost-price inputstyle' name='goods[ladder][ladder_cost_price]' value='<{$goods.ladder.ladder_cost_price}>' vtype='positive'  style="width:60px" maxlength="25"/></td>
	</tr>
  <tr>
    <th><{t}>货号：<{/t}></th>
    <td><{input type="text" value=$product.bn key="bn" name="goods[product][0][bn]" maxlength="30" }></td>
  </tr>
  <tr>
    <th><{t}>重量：<{/t}></th>
    <td><{input type="unsigned" key="weight" value=$product.weight name="goods[product][0][weight]" style="width:60px" maxlength="25" }><{t}>千克(kg)<{/t}></td>
  </tr>
	<tr>
    <th><{t}>体积：<{/t}></th>
    <td><{input type="unsigned" key="capacity" value=$goods.capacity name="goods[capacity]" style="width:60px" maxlength="25" }><{t}>立方米(m³)<{/t}></td>
  </tr>
  <{if $goods.type.is_physical || $gtype.0.is_physical}>
  <tr>
    <th><{t}>库存：<{/t}></th>
    <td>
    <{permission perm_id='editstore'}>
    <{input type="unsigned" key="store" value=$product.store name="goods[product][0][store]" style="width:60px" maxlength="25" }>
    <{input type="hidden"  value=$product.freez name="goods[product][0][freez]" style="width:60px" maxlength="25" }>
    <{if $product.freez}>
    <span class="notice-inline"><{t}>当前冻结库存<{/t}> <font size="3" color="red"><{$product.freez}></font><{t}> ，库存不能小于冻结库存<{/t}></span></td>
    <{/if}>
    <{/permission}>
    </td>
  </tr>
  <{/if}>
    <{if $storeplace == 'true'}>
    <tr>
        <th><{t}>货位：<{/t}></th>
        <td><{input type="text" key="store_place" value=$goods.store_place name="goods[product][0][store_place]" maxlength="25" }></td>
    </tr>
    <{/if}>
    <{if $spec}>
  <tr>
    <th><{t}>规格：<{/t}></th>
    <td style="padding:4px 0">
        <{button icon="btn_add.gif" label=$___b2c="开启规格"|t:'b2c' app="desktop" id="open_spec" }>
        <span class="notice-inline"><{t}>开启规格前先填写以上价格等信息，可自动复制信息到货品<{/t}></span>
    </td>
  </tr>
  <{/if}>
</tbody>
</table>
<div style="display:none;">
<h2 class="head-title"><{t}>规格<{/t}></h2>
<div class="goods-spec-detail">
    <{button label="label" label=$___b2c="编辑"|t:'b2c' app="desktop" class="selectspec"}>
    <div class="goods-spec-selected">
        <dl>
            <dt><{t}>已经启动的规格项:<{/t}></dt>
            <{foreach from=$goods.used_spec item=u_spec}>
            <dd><{$u_spec.spec_name}>(<{$u_spec.nums}>)</dd>
            <{/foreach}>
        </dl>
        <p class="goods-num">
              <{t}>已生成货品<{/t}>(<{$goods.product_num}>)
        </p>
    </div>
    <{button label="label" label=$___b2c="关闭"|t:'b2c' class="closespec"}>
</div>
</div>
<input name="new_goods_spec" type='hidden' id='new_goods_spec' value=''/>
<script>
function toJSON(element, string) {
    var json = {};
    element.getElements('input,select,textarea').each(function(el){
        if((el.type == 'checkbox' || el.type=='radio') && !el.checked || !el.name || !el.value || el.disabled) return;
        json[el.name] = el.value;
    });
    return string ? JSON.encode(json) : json;
}
<{if $spec}>
var activeProduct = <{$activeProduct|default:'false'}>;
var type_id = $('gEditor-GType-input').value;
$('open_spec').addEvent('click',function(e){
    if(activeProduct) return alert('<{t}>此商品尚有未处理的订单，不能开启规格。<{/t}>')
    if($('gEditor-GType-input').getValue()=='1'){
        alert('<{t}>请先选择商品类型！<{/t}>');
        $('gEditor-GType-input').focus();
        return false;
    }
    var hsspec=new Hash();
    $ES('#nospec_body input[key]').each(function(ipt){
        if(ipt.value.trim().length)
        hsspec.set(ipt.get('key'),ipt.value);
    });
    $('goods-spec').store('hsspec',hsspec);
    var url = 'index.php?app=b2c&ctl=admin_products&act=set_spec_index&nospec=1&'+$$('.pic-area')[0].toQueryString()+'&type_id=' + type_id + '&'+$('goods-spec').toQueryString();
    var goods_id = '<{$goods.goods_id}>';
    if(goods_id){
        url = url + '&goods_id=' + goods_id;
    }
    window.open(url,'new');
});

    $$('.goods-spec-detail .selectspec')[0].addEvent('click',function(e){
        window.open('index.php?app=b2c&ctl=admin_products&act=set_spec_index&nospec=0&'+$$('.pic-area')[0].toQueryString()+'&type_id=' + type_id + '&goods_id=<{$goods.goods_id}>','edit');
    });
    $$('.goods-spec-detail .closespec')[0].removeEvents('click').addEvent('click',function(e){
       if(e&&!confirm('<{t}>关闭后现有已添加的货品数据将全部丢失，确定要关闭规格吗？<{/t}>'))return;
       new Request.HTML({
       url:'index.php?app=b2c&ctl=admin_goods_editor&act=nospec',method:'post',
       update:'goods-spec',data:'goods_id=<{$goods.goods_id}>&type_id='+type_id}).send();
    });

<{/if}>
function isNew(data){
        var goodsNum,specJson;

        goodsNum = JSON.decode(data).productNum;
        specJson = JSON.decode(data).used_spec;

        $$('#goods-spec table.advui').setStyle('display','none');
        $$('#goods-spec table.advui').getNext().setStyle('display','block');

        $('new_goods_spec').set('value',data);

        $$('.goods-spec-detail .goods-spec-selected p')[0].innerHTML = "<{t}>已生成货品<{/t}>("+goodsNum+")";


        $$('.goods-spec-detail .goods-spec-selected dl dd').destroy();

        specJson.each(function(item){
            new Element('dd',{
                html:item.spec_name+'('+item.nums+')'
            }).inject($$('.goods-spec-detail .goods-spec-selected dl dt')[0],'after');
        });
}
</script>
